package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Department;
import cn.wolfcode.mapper.DepartmentMapper;
import cn.wolfcode.result.QueryObject;
import cn.wolfcode.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 部门业务实现类
 * @Author: 伍家钰
 * @Date: 2020/7/10 13:42
 * @Version: 1.0
 */
@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void delete(Long id) {
        departmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void save(Department department) {
        departmentMapper.insert(department);
    }

    @Override
    public Department selectById(Long id) {
        Department department = departmentMapper.selectByPrimaryKey(id);
        return department;
    }

    @Override
    public List<Department> selectAll() {
        List<Department> departments = departmentMapper.selectAll();
        return departments;
    }

    @Override
    public void update(Department department) {
        departmentMapper.updateByPrimaryKey(department);
    }

    @Override
    public PageInfo<Department> query(QueryObject qo) {
        // 开始分页,插入当前页和每页显示的数据
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        //查询数据总数
        List<Department> departments = departmentMapper.selectForList(qo);
        return new PageInfo<Department>(departments);
    }
}
